package com.sxu.demo;

import java.util.concurrent.SynchronousQueue;

public class test1 {
    public static void main(String[] args) throws InterruptedException {
        // SynchronousQueue
        SynchronousQueue<Integer> queue= new SynchronousQueue<Integer>();
        new Thread(() -> {
            try {
                System.out.println("Putting...1");
                queue.put(1);
                System.out.println("Putted...1");

                System.out.println("Putting...2");
                queue.put(2);
                System.out.println("Putted...2");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"t1").start();

        Thread.sleep(1);

        new Thread(() -> {
            try {
                System.out.println("Taking...1");
                queue.take();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"t2").start();

        Thread.sleep(1);

        new Thread(() -> {
            try {
                System.out.println("Taking...2");
                queue.take();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"t3").start();


    }
}
